home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / opndor / ex_music.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-26  |  5.8 KB  |  154 lines

  1. /* EX_MUSIC.C - Example program plays "Happy Birthday" to the remote user,   */
  2. /*              if possible. See the manual for instructions on how to       */
  3. /*              compile this program.                                        */
  4. /*                                                                           */
  5. /*              This program shows how to do the following:                  */
  6. /*                                                                           */
  7. /*                 - Demonstrates how to play sounds effects or music on a   */
  8. /*                   remote terminal program that supports the so-called     */
  9. /*                   "ANSI music" standard.                                  */
  10. /*                 - Shows how to send text to the remote system without it  */
  11. /*                   being displayed on the local screen.                    */
  12.  
  13.  
  14. /* The opendoor.h file must be included by any program using OpenDoors. */
  15. #include "opendoor.h"
  16.  
  17. #include <string.h>
  18.  
  19. /* Functions for playing "ANSI music" and testing "ANSI music" capabilities. */
  20. void PlayANSISound(char *pszSounds);
  21. char TestSound(void);
  22.  
  23. /* Variable indicates whether or not sound is on */
  24. char bSoundEnabled = TRUE;
  25.  
  26.  
  27. /* The main() or WinMain() function: program execution begins here. */
  28. #ifdef ODPLAT_WIN32
  29. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  30.    LPSTR lpszCmdLine, int nCmdShow)
  31. #else
  32. int main(int argc, char *argv[])
  33. #endif
  34. {
  35.    /* Handle standard command-line options and perform other needed setup. */
  36. #ifdef ODPLAT_WIN32
  37.    od_control.od_cmd_show = nCmdShow;
  38.    od_parse_cmd_line(lpszCmdLine);
  39. #else
  40.    od_parse_cmd_line(argc, argv);
  41. #endif
  42.  
  43.    /* Display introductory message. */
  44.    od_printf("This is a simple door program that will play the song Happy Birthday\n\r");
  45.    od_printf("tune on the remote system, if the user's terminal program supports ANSI\n\r");
  46.    od_printf("music. Music is not played on the local speaker, as BBS system operators\n\r");
  47.    od_printf("do not wish to have the BBS computer making sounds at any time of the day\n\r");
  48.    od_printf("or night. However, the program can easily be modified to also echo sound to\n\r");
  49.    od_printf("the local speaker.\n\r\n\r");
  50.  
  51.  
  52.    /* Test whether user's terminal supports "ANSI music". */
  53.    TestSound();
  54.  
  55.  
  56.    /* Send birthday greetings to the remote user. */
  57.  
  58.    /* Clear the screen. */
  59.    od_clr_scr();
  60.  
  61.    /* Display a message. */
  62.    od_printf("\n\rHappy Birthday!\n\r");
  63.  
  64.    /* If "ANSI music" is available, play "Happy Birthday". */
  65.    PlayANSISound("MBT120L4MFMNO4C8C8DCFE2C8C8DCGF2C8C8O5CO4AFED2T90B-8B-8AFGF2");
  66.  
  67.    /* Reset sound after finished playing. */
  68.    PlayANSISound("00m");
  69.  
  70.  
  71.    /* Wait for user to press a key before returning to the BBS. */
  72.    od_printf("\n\rPress any key to return to BBS...\n\r");
  73.    od_get_key(TRUE);
  74.    od_exit(0, FALSE);
  75.    return(0);
  76. }
  77.  
  78.  
  79. /* Function to test whether the user's terminal program supports ANSI music. */
  80. /* You can either do this every time the user uses your program, or only the */
  81. /* first time they use the program, saving the result in a data file.        */
  82. char TestSound(void)
  83. {
  84.    /* Variable to store user's response to question. */
  85.    char chResponse;
  86.  
  87.    /* Display description of test to user. */
  88.    od_printf("We need to know whether or not your terminal program supports ANSI music.\n\r");
  89.    od_printf("In order to test this, we will send a short ANSI music sequence. We will then\n\r");
  90.    od_printf("ask whether or not you heard any sound.\n\r");
  91.    od_printf("Press any key to begin this test... ");
  92.  
  93.    /* Wait for user to press a key to begin. */
  94.    od_get_key(TRUE);
  95.    od_printf("\n\r\n\r");
  96.  
  97.    /* Temporarily enable sound. */
  98.    bSoundEnabled = TRUE;
  99.  
  100.    /* Send sound test sequence. */
  101.    PlayANSISound("MBT120L4MFMNO4C8C8DC");
  102.  
  103.    /* Reset sound after finished test. */
  104.    PlayANSISound("00m");
  105.  
  106.    /* Clear screen and ask whether user heard the sound. */
  107.    od_clr_scr();
  108.    od_printf("Did you just hear sound from your speaker? (Y/n)");
  109.    chResponse = od_get_answer("YN");
  110.  
  111.    /* Set ANSI music on/off according to user's response. */
  112.    bSoundEnabled = (chResponse == 'Y');
  113.    
  114.    return(bSoundEnabled);
  115. }
  116.  
  117.  
  118. /* Function to play "ANSI" music or sound effects. The play_sound() function
  119.  * can be called with a string of 0 to 250 characters. The caracters of the
  120.  * string define what sounds should be played on the remote speaker, as
  121.  * follows:
  122.  *
  123.  *      A - G       Musical Notes
  124.  *      # or +      Following A-G note means sharp
  125.  *      -           Following A-G note means flat
  126.  *      <           Move down one octave
  127.  *      >           Move up one octave
  128.  *      .           Period acts as dotted note (extend note duration by 3/2)
  129.  *      MF          Music Foreground (pause until finished playing music)
  130.  *      MB          Music Background (continue while music plays)
  131.  *      MN          Music note duration Normal (7/8 of interval between notes)
  132.  *      MS          Music note duration Staccato
  133.  *      ML          Music note duration Legato
  134.  *      Ln          Length of note (n=1-64, 1=whole note, 4=quarter note, etc)
  135.  *      Pn          Pause length (same n values as Ln above)
  136.  *      Tn          Tempo, n=notes/minute (n=32-255, default n=120)
  137.  *      On          Octave number (n=0-6, default n=4)
  138.  */
  139.  
  140. void PlayANSISound(char *pszSounds)
  141. {
  142.    /* Beginning of sound sequence. */
  143.    char szStartSound[255] = {27, '[', '\0'};
  144.  
  145.    /* Abort if sound is not enabled. */
  146.    if(!bSoundEnabled) return;
  147.  
  148.    /* Send sequence to start playing sound to remote system only. */
  149.    od_disp(szStartSound, strlen(szStartSound), FALSE);
  150.  
  151.    /* Send the sounds codes to the remote system only. */
  152.    od_disp(pszSounds, strlen(pszSounds), FALSE);
  153. }
  154.